package com.sun.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sun.mapper.OneLMapper;
import com.sun.mapper.OneWMapper;
import com.sun.mapper.ScoreMapper;
import com.sun.mapper.ScoreWMapper;
import com.sun.pojo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


import javax.servlet.http.HttpSession;
import java.util.Collection;
import java.util.List;

@Controller
public class ScoreController {


    @Autowired
    private ScoreMapper scoreMapper;
    @Autowired
    private ScoreWMapper scoreWMapper;

    @Autowired
    private OneLMapper oneLMapper;




    /*
    * 理科
    * */
    @RequestMapping("/score/{pageNo}")
    public Object page(@PathVariable("pageNo") Integer pageNo,
                       @RequestParam(value = "score",defaultValue = "score")  String score,
//                       @RequestParam(value = "year",defaultValue = "2021")  Integer year,
                       Model model
    ) {
        PageHelper.startPage(pageNo,10);
        List<HeannScoreL> list = scoreMapper.selectAll();
        PageInfo<HeannScoreL> page = new PageInfo<>(list,5);
        model.addAttribute("list",page);
        model.addAttribute("score",score);
        return "score/list";
    }

//    @RequestMapping("/score/{year}")
//    public Object year(@RequestParam(value = "score",defaultValue = "score")  String score,
//                       @PathVariable(value = "year")  Integer year,
//                       Model model
//    ) {
//        PageHelper.startPage(1,10);
//        List<HeannScoreL> list = scoreMapper.selectByYear(year);
////        List<HeannScoreL> list = scoreMapper.selectAll();
//        PageInfo<HeannScoreL> page = new PageInfo<>(list,5);
//        model.addAttribute("list",page);
//        model.addAttribute("score",score);
//        return "score/list";
//    }

    @RequestMapping("/l/select21")
    @ResponseBody
    public List<HeannScoreL> selectByName(
    ){
        List<HeannScoreL> all = scoreMapper.select21();
        System.out.println(all);
        return all;
    }
    @RequestMapping("/l/select20")
    @ResponseBody
    public List<HeannScoreL> select20(
    ){
        List<HeannScoreL> all = scoreMapper.select20();
        System.out.println(all);
        return all;
    }
    @RequestMapping("/l/select19")
    @ResponseBody
    public List<HeannScoreL> select19(
    ){
        List<HeannScoreL> all = scoreMapper.select19();
        System.out.println(all);
        return all;
    }

    @RequestMapping("/score")
    public String po(@RequestParam(value = "pageNo1",defaultValue = "0") Integer pageNo1,
                     @RequestParam(value = "score",defaultValue = "score")  String score,
                     Model model){
        PageHelper.startPage(pageNo1,10);
        List<HeannScoreL> list = scoreMapper.selectAll();
        PageInfo<HeannScoreL> page1 = new PageInfo<>(list,5);
        model.addAttribute("list",page1);
        model.addAttribute("score",score);
        return "score/list";
        }
    @RequestMapping("/scores")
    public String select(@RequestParam("name") String name,
//                         @PathVariable("pageNo") Integer pageNo,
                         @RequestParam(value = "score",defaultValue = "score")  String score,
                         Model model){
        List<HeannScoreL> list = scoreMapper.selectDate(name);
        PageInfo<HeannScoreL> page1 = new PageInfo<>(list, 5);
        model.addAttribute("list", page1);
        model.addAttribute("score",score);
        return "score/list";
    }
    @RequestMapping("/yuce")
    public String list1( Model model){
        List<HeannScoreL> list = scoreMapper.selectDate11("新乡学院","本科二批");
        int t1 = Integer.parseInt(list.get(0).getMinOrder());
        int t2 = Integer.parseInt(list.get(1).getMinOrder());
        int t3 = Integer.parseInt(list.get(2).getMinOrder());
        int mun;
        mun = (t1*2+t2*3+t3*5)/10;
        System.out.println(mun);
        List<OneByOneL> li = oneLMapper.selectData(mun);
        System.out.println(li);
        mun = li.get(0).getScore();
        PageInfo<HeannScoreL> page1 = new PageInfo<>(list, 5);
//        PageInfo<OneByOneL> page = new PageInfo<>(li, 5);
        model.addAttribute("list", page1);
        model.addAttribute("mun", mun);

        return "yuce/list";
    }
    @RequestMapping("/yw")
    public String listw(Model model){
        List<HeannScoreW> list = scoreWMapper.selectDate("新乡学院");
        int t1 = Integer.parseInt(list.get(0).getMinOrder());
        int t2 = Integer.parseInt(list.get(1).getMinOrder());
        int t3 = Integer.parseInt(list.get(2).getMinOrder());
        int mun;
        mun = (t1*2+t2*3+t3*5)/10;
        System.out.println(mun);
        List<OneByOneL> li = oneLMapper.selectData1(mun);
        System.out.println(li);
        mun = li.get(0).getScore();
        PageInfo<HeannScoreW> page1 = new PageInfo<>(list, 5);
//        PageInfo<OneByOneL> page = new PageInfo<>(li, 5);
        model.addAttribute("list", page1);
        model.addAttribute("mun", mun);

        return "yucew/list";
    }

    @RequestMapping("/yucel")
    public String yuce(@RequestParam("name") String name,
//                         @PathVariable("pageNo") Integer pageNo,
                         @RequestParam(value = "yucel",defaultValue = "yucecl")  String score,
                         Model model){
        List<HeannScoreL> list = scoreMapper.selectDate(name);
        int t1 = Integer.parseInt(list.get(0).getMinOrder());
        int t2 = Integer.parseInt(list.get(1).getMinOrder());
        int t3 = Integer.parseInt(list.get(2).getMinOrder());
       int mun;
       mun = (t1*2+t2*3+t3*5)/10;
        System.out.println(mun);
        List<OneByOneL> li = oneLMapper.selectData(mun);
        System.out.println(li);
        mun = li.get(0).getScore();
        PageInfo<HeannScoreL> page1 = new PageInfo<>(list, 5);
//        PageInfo<OneByOneL> page = new PageInfo<>(li, 5);
        model.addAttribute("list", page1);
        model.addAttribute("mun", mun);
        model.addAttribute("score",score);
        return "yuce/list";
    }

    @RequestMapping("/yuceW")
    public String yw(@RequestParam("name") String name,
//                         @PathVariable("pageNo") Integer pageNo,
                       @RequestParam(value = "yucew",defaultValue = "yucew")  String score,
                       Model model){
        List<HeannScoreW> list = scoreWMapper.selectDate(name);
        int t1 = Integer.parseInt(list.get(0).getMinOrder());
        int t2 = Integer.parseInt(list.get(1).getMinOrder());
        int t3 = Integer.parseInt(list.get(2).getMinOrder());
        int mun;
        mun = (t1*2+t2*3+t3*5)/10;
        System.out.println(mun);
        List<OneByOneL> li = oneLMapper.selectData1(mun);
        System.out.println(li);
        mun = li.get(0).getScore();
        PageInfo<HeannScoreW> page1 = new PageInfo<>(list, 5);
//        PageInfo<OneByOneL> page = new PageInfo<>(li, 5);
        model.addAttribute("list", page1);
        model.addAttribute("mun", mun);
        model.addAttribute("score",score);
        return "yucew/list";
    }



    @RequestMapping("/l/{name}")
    @ResponseBody
    public List<HeannScoreL> selectByNameL( @PathVariable("name") String name
    ){
        List<HeannScoreL> all = scoreMapper.selectByName(name);
        System.out.println(all);
        return all;
    }

    /*
     * 文科
     * */
    @RequestMapping("/scoreW/{pageNo}")
    public Object pagew(@PathVariable("pageNo") Integer pageNo,
                        @RequestParam(value = "score",defaultValue = "scoreW")  String score,
                       Model model
    ) {
        PageHelper.startPage(pageNo,10);
        List<HeannScoreW> list = scoreWMapper.selectAll();
        PageInfo<HeannScoreW> page = new PageInfo<>(list,5);
        model.addAttribute("list",page);
        model.addAttribute("score",score);
//        model.addAttribute("pageNo1",pageNo1);
//        System.out.println(pageNo1);
//        return page;
        return "score/list";
    }


    @RequestMapping("/scoreW")
    public String pow(@RequestParam(value = "pageNo1",defaultValue = "0") Integer pageNo1,
                      @RequestParam(value = "score",defaultValue = "scoreW")  String score,
                     Model model){
        PageHelper.startPage(pageNo1,10);
        List<HeannScoreW> list = scoreWMapper.selectAll();
        PageInfo<HeannScoreW> page1 = new PageInfo<>(list,5);
        model.addAttribute("list",page1);
        model.addAttribute("score",score);
        return "score/list";
    }

    @RequestMapping("/scoreWs")
    public String selectW(@RequestParam("name") String name,
//                         @PathVariable("pageNo") Integer pageNo,
                          @RequestParam(value = "score",defaultValue = "scoreW")  String score,
                         Model model){
        List<HeannScoreW> list = scoreWMapper.selectDate(name);
        PageInfo<HeannScoreW> page1 = new PageInfo<>(list, 5);
        model.addAttribute("list", page1);
        model.addAttribute("score",score);
        return "score/list";
    }
    @RequestMapping("/w/{name}")
    @ResponseBody
    public List<HeannScoreW> selectByName( @PathVariable("name") String name
    ){
        List<HeannScoreW> all = scoreWMapper.selectByName(name);
        System.out.println(all);
        return all;
    }




    @RequestMapping("/w/select21")
    @ResponseBody
    public List<HeannScoreW> select21(
    ){
        List<HeannScoreW> all = scoreWMapper.select21();
        System.out.println(all);
        return all;
    }
    @RequestMapping("/w/select20")
    @ResponseBody
    public List<HeannScoreW> selectw20(
    ){
        List<HeannScoreW> all = scoreWMapper.select20();
        System.out.println(all);
        return all;
    }
    @RequestMapping("/w/select19")
    @ResponseBody
    public List<HeannScoreW> selectw19(
    ){
        List<HeannScoreW> all = scoreWMapper.select19();
        System.out.println(all);
        return all;
    }


    @RequestMapping("/score/echarts")
    public String Echarts(){
        return "score/echarts";
    }


}
